$(function(){
	$("#gaoliangDS05").removeClass("sub-menu-link").addClass("selected");
	var randomN = getRandomNum();
	$("#merOrderNum").val(randomN);	
	
	$("#defButton").on("click",function(){
		var randomN = getRandomNum();
		// 交易时间
		$("#tranDateTime").val(getCurentTime());
		// 国付宝服务器时间
		$("#gopayServerTime").val(getCurentTime());
		//P2P客户id
		$("#thirdPartyId").val(getCurentTime());
		// 商户流水号
		$("#merOrderNum").val(randomN);
		//设置商户识别码
		$("#verficationCode").val("11111aaaaa");
		//设置域名
		var protocol = window.location.protocol ;
		var host = window.location.host;
		var backGroundURI = '/webtest/result/webclient/background.do';
		$("#backgroundMerUrl").val(protocol +'//'+host+backGroundURI);
	})
	
	$("#submitBtn").on("click",function(){
		$("#payForm").submit();
	})
	
	
	$.formValidator.initConfig({
		validatorgroup : "1",
		formid : "payForm",
		onerror : function(input1, input2) {
			return false;
		}
	});
	
	$("#version").formValidator({
		onshow : " "
	}).inputValidator({
		min : 1,
		onerror : "版本号不允许为空！"
	}).functionValidator({
		fun : function(val) {
			if (val != "1.0") {
				return "版本号必须为1.0";
			} else {
				return true;
			}
		}
	});
	
	$("#charset").formValidator({
		onshow : " "
	}).inputValidator({
		min : 1,
		onerror : "字符集不允许为空！"
	});
	
	$("#tranCode").formValidator({
		onshow : " "
	}).inputValidator({
		min : 1,
		onerror : "交易码不允许为空！"
	}).functionValidator({
		fun : function(val) {
			if (val != "DS05") {
				return "交易码必须为 DS05";
			} else {
				return true;
			}
		}
	});
	
	$("#merchantID").formValidator({
		onshow : " "
	}).inputValidator({
		min : 1,
		onerror : "商户ID不允许为空！"
	});
	
	$("#merOrderNum").formValidator({
		onshow : " "
	}).inputValidator({
		min : 1,
		onerror : "订单号不允许为空！"
	});
	
	$("#tranAmt").formValidator({
		onshow : " "
	}).inputValidator({
		min : 1,
		onerror : "交易金额不允许为空！"
	});
	
	$("#currencyType").formValidator({
		onshow : " "
	}).inputValidator({
		min : 1,
		onerror : "币种不允许为空！"
	});
	
	$("#tranDateTime").formValidator({
		onshow : " "
	}).inputValidator({
		min : 1,
		onerror : "交易时间不允许为空！"
	});
	
	$("#gopayServerTime").formValidator({
		onshow : " "
	}).inputValidator({
		min : 1,
		onerror : "国付宝服务器时间不允许为空！"
	});
	

	$("#language").formValidator({
		onshow : " "
	}).inputValidator({
		min : 1,
		onerror : "网关语言版本不允许为空！"
	});
	
	$("#virCardNoIn").formValidator({
		onshow : " "
	}).inputValidator({
		min : 1,
		onerror : "国付宝转入账户不允许为空！"
	});
	$("#contractNo").formValidator({
		onshow : " "
	}).inputValidator({
		min : 1,
		onerror : "委托代收授权编码不允许为空！"
	});
	$("#backgroundMerUrl").formValidator({
		onshow : " "
	}).inputValidator({
		min : 1,
		onerror : "后台通知地址不允许为空！"
	});  
})

function getRandomNum() {
	window.random_code_base = (([ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J',
			'K', 'M', 'N' ])[new Date().getMonth()])
			+ '_' + (Math.random() * 10000000000 + '').substring(0, 4);	
	return window.random_code_base + "_" + (window.random_code_index++);
}

/**
 * 获取当前时间
 * 格式为20160323165212的时间字符串
 * lixu 2016-03-23 17:10:09
 */
function getCurentTime(){ 
    var currentTime;
    var now = new Date();
   
    var year = now.getFullYear();
    var month = now.getMonth() + 1;
    var day = now.getDate();
   
    var hh = now.getHours();
    var mm = now.getMinutes();
    var ss = now.getSeconds();  

    if(month < 10) month = '0' + month;
    if(day < 10) day= '0' + day;
    if(hh < 10) hh = '0' + hh;
    if(mm < 10) mm = '0' + mm; 
    if(ss < 10) ss = '0' + ss; 

    currentTime = year+month+day+hh+mm+ss;

    return currentTime; 
} 